import { _decorator, Collider2D, Component, IPhysics2DContact, Node, RenderTexture } from 'cc';
import { EnemyController } from './EnemyController';
import { GameManager } from './GameManager';
import PlayerController from '../PlayerController';
const { ccclass, property } = _decorator;

@ccclass('Enemy_Monster')
export class Enemy_Monster extends EnemyController {
    protected onLoad(): void {
        super.onLoad();
    }

    protected start(): void {
        super.start();
    }

    attack() {
        if (this.IsAttack || !this.InRange || this.IsDie) return;
        this.IsAttack = true;
        this.showTips();
        this.scheduleOnce(() => {
            this.IsAttack = false;
            this.hideTips();
            if (!this.InRange || GameManager.Instance.IsPause) return;//玩家不在攻击范围内 --- 暂停游戏
            this.attack();
            //对玩家造成伤害
            PlayerController.Instance.hit(this.Harm);
        }, 1);
    }

    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 只在两个碰撞体开始接触时被调用一次
        this.InRange = true;
        this.attack();
    }

    onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 只在两个碰撞体开始接触时被调用一次
        this.InRange = false;
    }

}


